package com.lzp.systemopt.camera.view

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import com.lzp.systemopt.R
import com.lzp.systemopt.camera.Constants

/**
 * @description:拍照按钮
 * @author: lxp
 * @date: 2021/12/14 下午3:42
 */
class CapturePictureButton : AppCompatImageView {
    private var btnState = Constants.STATE_INIT

    constructor(context: Context) : this(context, null)

    @SuppressLint("CustomViewStyleable")
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        val stateDrawable = getStateDrawable(btnState)
        setImageResource(stateDrawable)
    }

    fun setState(@Constants.CameraBtnState btnState: Int) {
        if (this.btnState == btnState) return
        this.btnState = btnState
        val stateDrawable = getStateDrawable(btnState)
        setImageResource(stateDrawable)
    }

    private fun getStateDrawable(@Constants.CameraBtnState btnState: Int): Int {
        return when (btnState) {
            Constants.STATE_DISABLE -> {
                R.mipmap.ic_btn_capture_disable
            }
            Constants.STATE_INIT -> {
                R.mipmap.photo
            }
            Constants.STATE_PREVIEW -> {
                R.mipmap.ic_btn_capture_normal
            }
            else -> {
                R.mipmap.photo
            }
        }
    }

    fun getState(): Int {
        return btnState
    }
}